package ThreadPool;

import ThreadDemo.Callable.MyCallable;
import ThreadDemo.Runnable.MyRunnable;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MyThreadPool {
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,// 核心线程数量
                5,// 最大线程数
                10,// 空闲线程最大存活时间
                TimeUnit.MINUTES,// 时间单位
                new ArrayBlockingQueue<>(10),// 任务队列
                Executors.defaultThreadFactory(),// 创建线程工厂
                new ThreadPoolExecutor.AbortPolicy());// 任务的拒绝策略
        pool.submit(new MyRunnable());
        pool.submit(new MyRunnable());

        pool.shutdown();
    }
}
